<template>
  <div class="app-container">
    <!-- 客户信息 -->
    <customerInformation ref="customerInformation" v-model="form" :state='state' />
    <!-- 车辆信息 -->
    <carInformationDetail ref="carInformationDetail" v-model="form" :state='state' />
    <!-- 供应商信息 -->
    <supplierInformation ref="supplierInformation" v-model="form" :state='state' />
    <!-- 申请信息 -->
    <cationInformation ref="cationInformation" v-model="form" :state='state' />
  </div>
</template>

<script>
import customerInformation from "./components/customerInformation";
import carInformationDetail from "./components/carInformationDetail";
import supplierInformation from "./components/supplierInformation";
import cationInformation from "./components/cationInformation";

export default {
  // 新增委外收车申请 工作流页面
  name: 'PickUpTheCarApplyFlow',
  props: {
    value: {
      type: Object,
      default: {},
    },
    state: {
      type: String,
      default: '',
    },
  },
  computed: {
    form: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit("input", val);
      },
    },
  },
  components: {
    customerInformation,
    carInformationDetail,
    supplierInformation,
    cationInformation
  },
  data() {
    return {};
  },
  created() {

  },
  methods: {
    valid() {
      return new Promise(async (resolve) => {
        let result = true;
        let refs = Object.values(this.$refs);
        for (let index = 0; index < refs?.length; index++) {
          const ref = refs[index];
          if (Object.prototype.toString.call(ref) == "[object Array]") {
            for (let i = 0; i < ref.length; i++) {
              const element = ref[i];
              if (element?.valid) {
                let rc = await element?.valid?.();
                result = result && rc;
              }
              if (element?.validate) {
                let rf = await this._valid(ref);
                result = result && rf;
              }
              if (element?.form_validate) {
                let rf = await this._valid(ref, "form_validate");
                result = result && rf;
              }
            }
          } else {
            if (ref?.valid) {
              let rc = await ref?.valid?.();
              result = result && rc;
            }
            if (ref?.validate) {
              let rf = await this._valid(ref);
              result = result && rf;
            }
            if (ref?.form_validate) {
              let rf = await this._valid(ref, "form_validate");
              result = result && rf;
            }
          }
        }
        resolve(result);
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  overflow: auto !important;
}
</style>
